package com.sinopec.pi.scalaguide

/*
 * class and object usage.
 */
class Animal(private val name: String, private val age: Int = 0) {

    def getName: String = name

    def getAge: Int = age

    override def toString: String = {
        s"name: ${name}, age: ${age}"
    }
}

object Animal {
    def apply(age: Int, name: String): Animal = {
        new Animal(name, age)
    }
}

object Main {
    def main(args: Array[String]): Unit = {
        // 使用 Animal.apply 方法创建对象
        val dog = Animal(1, "dog") // 等价于 new Animal("dog", 1)
        println(dog)
    }
}
